<template>
    <el-dialog class="elDialog" :title="wintitle" :visible.sync="isShow" width="80%" :lock-scroll="true" :close-on-click-modal="false">
        <div class="dialog">
            <zy-table :tableData="tableData" :tableColumn="tableColumn" :pageSize="pagination.pageSize" :total="pagination.total" @changePage="changePage"></zy-table>
        </div>
    </el-dialog>
</template>

<script>
import { column_1 } from './formConfig.js'
import zyTable from '@/components/common/zyTable.vue'
import { requestApi } from '@/requset/api'
export default {
    data() {
        return {
            wintitle: '',
            isShow: false,
            tableData: [],
            page: 1,
            pagination: {
                pageSize: null,
            },
            tableColumn: null,
            factory_id: null,
        }
    },
    components: { zyTable },
    methods: {
        doOpen(e, see = true) {
            this.isShow = true

            this.factory_id = e.factory_id
            this.search()
        },
        getList(obj) {
            obj.page = this.page
            requestApi('post', 'selfreport/factory/details', obj, true).then((res) => {
                let list = res.data.data

                if (res.data.code == 0 && list.length != 0) {
                    this.tableData = res.data.data
                    this.pagination = res.data.pagination
                } else {
                    if (list.length == 0) {
                        this.tableData = []
                        this.pagination = {}
                        return
                    }
                    this.$message({
                        type: 'info',
                        message: '网络异常或暂无数据，请稍后重试',
                    })
                }
            })
        },
        search() {
            this.getList({ factory_id: this.factory_id, page: this.page })
        },
        handle1(val) {
            let { device_id, new_time, sensor_id, feature_key } = val
            feature_key = this.removePrefix(feature_key)
            this.$router.push(`/index/diagnosis?device_id=${device_id}&time=${new_time}&sensor_id=${sensor_id}&key=${feature_key}`)
        },
        removePrefix(str) {
            if (str.startsWith('Z_') || str.startsWith('X_') || str.startsWith('Y_')) {
                return str.substring(2) // 去除前两个字符并返回剩余部分
            } else {
                return str // 如果不以指定的前缀开头，则返回原始字符串
            }
        },
        changePage(e) {
            this.page = e
            this.search()
        },
    },
    created() {
        this.tableColumn = column_1
        column[column.length - 1].buttons = [
            {
                text: '查看',
                click: (val) => this.handle1(val),
                icon: 'el-icon-s-comment',
            },
        ]
    },
}
</script>

<style lang="less">
.elDialog {
    .dialog {
        width: 88%;
        height: 60vh;
    }
}
</style>
